package main.Q1201_1300;

import java.util.ArrayList;
import java.util.List;

public class Q1221_1230 {
    public static void main(String[] args) {
        System.out.println("Question1221：分割平衡字符串");
        System.out.println("Question1222：可以攻击国王的皇后");
        System.out.println("Question1223：");
        System.out.println("Question1224：");
        System.out.println("Question1225：");
        System.out.println("Question1226：");
        System.out.println("Question1227：");
        System.out.println("Question1228：");
        System.out.println("Question1229：");
        System.out.println("Question1230：");
    }
}

class Question1221 {
    public int balancedStringSplit(String s) {
        int count = 0;
        int sum = 0, i = 0;
        while (i < s.length()) {
            sum += s.charAt(i) == 'R' ? 1 : -1;
            count += sum == 0 ? 1 : 0;
            i++;
        }
        return count;
    }
}

class Question1222 {
    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {
        List<String> qLocation = new ArrayList<>();
        List<List<Integer>> result = new ArrayList<>();
        for (int[] queen : queens) {
            qLocation.add(queen[0] + "-" + queen[1]);
        }
        int kRow = king[0], kCol = king[1];
        int i = kRow - 1, j = kCol - 1;
        while (i >= 0 && j >= 0) {// 国王左上
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            i--;
            j--;
        }
        i=kRow-1;
        j=kCol;
        while (i >= 0 && j >= 0) {// 国王正上
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            i--;
        }
        i=kRow-1;
        j=kCol+1;
        while (i >= 0 && j < 8) {// 国王右上
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            i--;
            j++;
        }
        i=kRow;
        j=kCol+1;
        while (i >= 0 && j < 8) {// 国王右侧
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            j++;
        }
        i=kRow+1;
        j=kCol+1;
        while (i < 8 && j < 8) {// 国王右下
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            j++;
            i++;
        }
        i=kRow+1;
        j=kCol;
        while (i < 8 && j < 8) {// 国王正下
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            i++;
        }
        i=kRow+1;
        j=kCol-1;
        while (i < 8 && j >= 0) {// 国王左下
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            i++;
            j--;
        }
        i=kRow;
        j=kCol-1;
        while (i < 8 && j >= 0) {// 国王左侧
            String curLocation = i + "-"+ j;
            if (qLocation.contains(curLocation)) {
                List<Integer> temp=new ArrayList<>();
                temp.add(i);
                temp.add(j);
                result.add(temp);
                break;
            }
            j--;
        }
        return result;
    }
}